# -*- coding:utf-8 -*-
import os
from PIL import Image
import pandas as pd

file_list = []
width_list = []
height_list = []
root_path = input('请输入 图片 所在地址:')
suffix = ['.jpg', '.png']

for dirpath, dirnames, files in os.walk(root_path):
    for file in files:
        file_path = os.path.join(dirpath, file)
        for suf in suffix:
            if file.endswith(suf):
                img = Image.open(file_path)
                file_list.append(file)
                width_list.append(img.size[0])
                height_list.append(img.size[1])

content_dict = {
    'dir_name':file_list,
    'width':width_list,
    'height':height_list
}

df = pd.DataFrame(content_dict)
csv_path = os.path.join(root_path,'image_size.csv')
df.to_csv(csv_path, encoding='utf_8_sig')
